package com.sgb.kjwl.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.core.util.Pair;
import androidx.fragment.app.Fragment;

import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.ProfessionalTeamPictureActivity;
import com.swgk.core.util.SharedPreferenceUtil;

import java.io.Serializable;
import java.util.List;

/**
 * @author younghow
 * @date 2020/10/29
 * description:页面跳转的工具类
 */
public class ActivityJump {

    public static void jumpToPhone(Context context,String phoneNumber){
        Intent dialIntent =  new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
        context.startActivity(dialIntent);
    }

    @SafeVarargs
    public static void jumpToActivity(Context context, Class<?> clazz, Pair<String, Serializable>...pair){
        context.startActivity(intentExtra(context,clazz,pair));
    }

    @SafeVarargs
    public static void jumpToActivityForResult(Activity context, Class<?> clazz, int request, Pair<String, Serializable>...pair){
        context.startActivityForResult(intentExtra(context.getApplicationContext(),clazz,pair),request);
    }
    @SafeVarargs
    public static void jumpToActivityForResult(Fragment context, Class<?> clazz, int request, Pair<String, Serializable>...pair){
        context.startActivityForResult(intentExtra(context.getContext(),clazz,pair),request);
    }

    @SafeVarargs
    private static Intent intentExtra(Context context, Class<?> clazz, Pair<String, Serializable>...pair){
        Intent intent = new Intent(context,clazz);
        for (Pair<String, Serializable> stringObjectPair : pair) {
            intent.putExtra(stringObjectPair.first,stringObjectPair.second);
        }
        return intent;
    }

    public static void showBigPicture(Context context, List<String> urls,int position){
        Intent intent = new Intent();
        intent.setClass(context, PhotoViewActivity.class);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) urls);
        intent.putExtra("goneBack",true);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
        context.startActivity(intent);
    }

    public static void showBigPicture(Context context, List<String> urls,int position,boolean gonepreview){
        Intent intent = new Intent();
        intent.setClass(context, PhotoViewActivity.class);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) urls);
        intent.putExtra("goneBack",true);
        intent.putExtra("gonepreview",gonepreview);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
        context.startActivity(intent);
    }
}
